<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
class Split50RecordationAndTransferTaxFactory{

    public function createSplitRecordationAndTransferTaxes($propertyTransferTax, $countyPropertyTransferTax, $recordationTax,
                                                                                $extraBuyerRecordationTax, $fees,
                                                                                $payerSpecialCase) {

        // CT-8 all recording fees will be charged to the buyer unless the user selects "Seller Pays All" then you will show the fees on the seller's side.
        // To put this another way, the default will always be that the recording fees will be to shown on the buyer's side.

        //print_r($recordationTax); exit();
        
        $halfRecordationTax = null;
        if ($recordationTax != null) {
            $halfRecordationTax = new RecordationTax($recordationTax->getName(), $recordationTax->getAmount() / 2.0);
        } else {
            $halfRecordationTax = null;
        }

        $zeroPropertyTransferTax = null;
        $halfPropertyTransferTax = null;
        if ($propertyTransferTax != null) {
            $zeroPropertyTransferTax = new StatePropertyTransferTax($propertyTransferTax->getName(), 0.0);
            $halfPropertyTransferTax = new StatePropertyTransferTax($propertyTransferTax->getName(), $propertyTransferTax->getAmount() / 2.0);
        } else {
            $zeroPropertyTransferTax = null;
            $halfPropertyTransferTax = null;
        }

        $halfCountyPropertyTransferTax;
        if ($countyPropertyTransferTax != null) {
            $halfCountyPropertyTransferTax = new CountyPropertyTransferTax($countyPropertyTransferTax->getName(), $countyPropertyTransferTax->getAmount() / 2.0);
        } else {
            $halfCountyPropertyTransferTax = null;
        }

        $recordationAndTransferTaxes = array();

        $zeroFees = FeeHelper::getCloneWithZeroValue($fees);
        
        //print_r($fees); 
        //print_r($zeroFees); exit();

        $buyerRecordationTax = null;
        if ($halfRecordationTax != null) {
            $buyerRecordationTax = new RecordationTax($halfRecordationTax->getName(), $halfRecordationTax->getAmount() + $extraBuyerRecordationTax);
        }

        if ($payerSpecialCase == null) 
        {
            //echo "ok"; exit();
            $recordationAndTransferTaxes[] = new RecordationAndTransferTaxes(
                    $halfPropertyTransferTax, $halfCountyPropertyTransferTax, $buyerRecordationTax,
                    $fees,
                    EPayer::Buyer);

            $recordationAndTransferTaxes[] = new RecordationAndTransferTaxes(
                    $halfPropertyTransferTax, $halfCountyPropertyTransferTax, $halfRecordationTax,
                    $zeroFees,
                    EPayer::Seller);
        } 
        else if ($payerSpecialCase == EPayerSpecialCase::SellerMustPayStateTax) 
        {
            $recordationAndTransferTaxes[] = new RecordationAndTransferTaxes(
                    $zeroPropertyTransferTax, $halfCountyPropertyTransferTax, $buyerRecordationTax,
                    $fees,
                    EPayer::Buyer);

            $recordationAndTransferTaxes[] = new RecordationAndTransferTaxes(
                    $propertyTransferTax, $halfCountyPropertyTransferTax, $halfRecordationTax,
                    $zeroFees,
                    EPayer::Seller);
        }

        return $recordationAndTransferTaxes;
    }
}
?>
